<%
If Request.Cookies("ASPLogin") <> "True" Then
Call Login()
End If
Sub Login ()
Dim cmd
Dim sql
Dim connstring
Dim fValidLogin
fValidLogin = False
connstring = Application("aspdb_ConnectionString")
If Request.Form("btnSubmit") <> "Submit Authorization" Then
'Show login form
%>
<html>
<head>
<title>Login</title>
</head>
<body bgcolor="#FFFFFF" link="#010187" vlink="#010187" alink="#010187"
onLoad="document.Form1.frmUserID.focus();">
<center>
(Note: You can test this form by using "user1" as the username and password)
<table border="2" cellpadding="6" width="80%">
<form action="<% = Request.ServerVariables("URL")%>?<%=Request.ServerVariables("QUERY_STRING")%>" method="POST" Name="Form1">
<input type="hidden" name="frmLogin" value="true">
<tr>
<td align="right"><font size="2"
face="Tahoma">User ID:</font></td>
<td><input type="text" size="20"
name="frmUserID" maxlength="10"></td>
</tr>
<tr>
<td align="right"><font size="2"
face="Tahoma">Password:</font></td>
<td><input type="password"
size="20" name="frmUserPass"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="btnSubmit"
value="Submit Authorization"></td>
</tr>
</form>
</table>
</center>
</body>
</html>
<%
Response.End
Else
Set cmd = Server.CreateObject("ADODB.Command")
With cmd
.ActiveConnection = connstring
.CommandText = "sp_AuthenticateUser"
.CommandType = adCmdStoredProc
'Add Parameters
.Parameters.Append .CreateParameter("@UserID", adVarChar, adParamInput, 20, Request.Form("frmUserID"))
.Parameters.Append .CreateParameter("@Password", adVarChar, adParamInput, 20, Request.Form("frmUserPass"))
'Add Output Parameter
.Parameters.Append .CreateParameter("@IsValid", adTinyInt, adParamOutput, , 0)
'Execute the function
.Execute , , adExecuteNoRecords
If IsNull(.Parameters("@IsValid").Value) Then
fValidLogin = False
Else
fValidLogin = CInt(.Parameters("@IsValid").Value) = 1
End If
End With
Set cmd = Nothing
If fValidLogin Then
'Set Cookie
Response.Cookies("ASPLogin") = "True"
Response.Cookies("Username") = Request.Form("frmUserID")
Else
'Show Invalid Login screen.
%>
<html>
<head>
<title>Login Failure</title>
</head>
<body bgcolor="#FFFFFF" link="#010187" vlink="#010187"
alink="#010187">
<center>
<table border="2" cellpadding="6" width="80%">
<tr>
<td><center>
<font size="2" face="Tahoma">UserID <%=request.form("frmUserID")%> and the password you provided
is not a valid user/password combination. <br>
<a href="<% = Request.ServerVariables("URL")%>"> Click here to retry...</center></td>
</tr>
</table>
</center>
</body>
</html>
<%
Response.End
End If 'Check user exists
End If
End Sub
%>